home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13827 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  876 b 

  1. Path: bigboote.WPI.EDU!cs!shura
  2. From: shura@cs.wpi.edu (Alexander Schelkin)
  3. Newsgroups: comp.lang.c++
  4. Subject: HELP: Virtual output stream functions
  5. Date: 27 Mar 1996 14:52:54 GMT
  6. Organization: Worcester Polytechnic Institute Computer Science Department
  7. Distribution: world
  8. Message-ID: <4jbko6$ivo@bigboote.WPI.EDU>
  9. NNTP-Posting-Host: owl.wpi.edu
  10.  
  11. I have a base class (Base) and several derived classes (Derived1, 
  12. Derived2, ...). How can I implement a virtual operator<<?
  13.  
  14. I would like to be able to do the following:
  15.  
  16. If I have operator<< for Base, Derived1 and Derived2.
  17.  
  18. Base* p1 = new Derived1;
  19. Base* p2 = new Derived2;
  20. cout << "Derived 1 " << (*p1) << endl;
  21. cout << "Derived 2 " << (*p2) << endl;
  22.  
  23. But in this case an output I got comes from Base class operator<<,
  24. not from the derived classes.
  25.  
  26. Please answer me to shura@cs.wpi.edu
  27.  
  28. Thanks a lot,
  29. Alexander Schelkin
  30.  
  31.  
  32.